<template>
  <basic-container>
    <avue-crud :option="option" :search.sync="search" :table-loading="loading" :data="data" :page.sync="page" :permission="permissionList" :before-open="beforeOpen" v-model="form" ref="crud" @row-del="rowDel" @search-change="searchChange" @search-reset="searchReset" @selection-change="selectionChange" @current-change="currentChange" @size-change="sizeChange" @refresh-change="refreshChange" @sort-change="sortChange" @on-load="onLoad">
      <template slot="menuRight">
        <el-button type="warning" size="small" plain icon="el-icon-download" v-if="permission.yzf_pay_record_export" @click="handleExport">导出
        </el-button>
      </template>

      <template slot-scope="{}" slot="rpiNoSearch">
        <select-page ref="searchRpiSelect" label="rpiName" value="rpiNo" :select.sync="search.rpiNo" :url="website.searchLink.merchantUrl" placeholder-text="商户" filter-key="searchParam"></select-page>
      </template>
      <template slot-scope="{}" slot="serviceNoSearch">
        <select-page ref="searchSerSelect" label="serviceName" value="serviceNo" :select.sync="search.serviceNo" :url="website.searchLink.serviceUrl" placeholder-text="服务商" filter-key="searchParam"></select-page>
      </template>
      <template slot-scope="{}" slot="topServiceNoSearch">
        <select-page ref="searchOrgSelect" label="serviceName" value="serviceNo" :select.sync="search.topServiceNo" :url="website.searchLink.orgUrl" placeholder-text="机构" filter-key="searchParam"></select-page>
      </template>

    </avue-crud>
  </basic-container>
</template>

<script>
import { getList, getExport } from "@/api/rb-pay/yzfpayrecord/yzf_pay_record";
import { mapGetters } from "vuex";
import selectPage from "@/components/select-page/select-page";

export default {
  components: {
    selectPage
  },
  data() {
    return {
      form: {},
      query: {},
      search: {},
      loading: true,
      excelBox: false,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      selectionList: [],
      option: {
        height: 'auto',
        calcHeight: 30,
        tip: false,
        border: true,
        index: true,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        viewBtn: true,
        selection: true,
        searchMenuSpan: 6,
        columnBtn: false,
        labelWidth: 140, //弹出表单的标题的统一宽度
        searchLabelWidth: 120, //搜索框标题宽度
        menuWidth:100,
        column: [
          {
            label: "支付订单号",
            prop: "orderNo",
            type: "input",
            overHidden:true,
            search: true,
            width: 150
            //sortable: true
          },
          
          {
            label: "商户号",
            searchLabel: "商户",
            search: true,
            prop: "rpiNo",
            type: "select",
            overHidden:true,
            width: 150
            //sortable: true
          },
          {
            label: "商户门头名称",
            prop: "rpiName",
            type: "input",
            overHidden:true,
            minWidth: 180

            //sortable: true
          },
          // {
          //   label: "翼支付商户号",
          //   prop: "mercId",
          //   type: "input",
          // },
          {
            label: "联系人",
            prop: "contactName",
            overHidden:true,
            search: true,
            type: "input"
            //sortable: true
          },
          {
            label: "联系方式",
            prop: "contactNum",
            type: "input",
            //sortable: true
            overHidden:true,
            search: true,
            minWidth: 120
          },
          {
            label: "省",
            prop: "provinceName",
            type: "input",
            //sortable: true
          },
          {
            label: "市",
            prop: "cityName",
            type: "input",
            //sortable: true
          },
          {
            label: "区",
            prop: "areaName",
            type: "input",
            //sortable: true
          },
          {
            label: "联系人地址",
            prop: "address",
            type: "input",
            minWidth: 180,
            overHidden:true
            //sortable: true
          },
          {
            label: "商户直属代理编号",
            prop: "serviceNo",
            type: "input",
            overHidden:true,
            width: 150
            //sortable: true
          },
          {
            label: "商户直属代理",
            prop: "serviceName",
            type: "input",
            overHidden:true,
            minWidth: 180
            //sortable: true
          },
          {
            label: "商户机构编号",
            searchLabel: "商户机构",
            search: true,
            prop: "topServiceNo",
            type: "input",
            overHidden:true,
            width: 150
          },
          {
            label: "商户机构",
            prop: "topServiceName",
            overHidden:true,
            minWidth: 180,
            type: "select"
          },
          {
            label: "付款时间",
            prop: "createTime",
            type: "input",
            overHidden:true,
            width: 150
          },
          {
            label: "付款金额",
            prop: "payAmount",
            type: "input"
          }
        ]
      },
      data: []
    };
  },
  computed: {
    ...mapGetters(["permission"]),
    permissionList() {
      return {
        viewBtn: this.vaildData(this.permission.yzf_pay_record_view, false),
        exportBtn: this.vaildData(this.permission.yzf_pay_record_export, false)
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(",");
    }
  },
  methods: {

    beforeOpen(done, type) {
      if (["edit", "view"].includes(type)) {
        // this.form
      }
      done();
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
    },
    handleExport() {
      let params ={
        ...this.search,
        current:'-1',
        size:'-1'
      }

      this.$confirm("是否导出用户数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        getExport(params).then((res) => {
            this.$message({
              type: "success",
              message: res.data.msg
            });
          },
          (error) => {
            window.console.log(error);
          }
        );
      });
    },
    uploadAfter(res, done) {
      this.excelBox = false;
      this.refreshChange();
      done();
    },
    sortChange(val) {
      if (val.order == "ascending") {
        //正序
        this.query.ascs = val.prop
        this.query.descs = ""
      } else {
        //倒序
        this.query.descs = val.prop
        this.query.ascs = ""
      }
      this.refreshChange();
    }
  }
};
</script>

<style></style>
